package com.vince.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 *  中文乱码问题
 *  
 *  
 *   
 * @author susp
 *
 */
@WebServlet("/info")
public class EncodingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doPost(request,response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    //用于解决get请求的中文乱码问题
//		String u=new String(request.getParameter("username").getBytes("iso-8895-1"),"utf-8");
		//可以解决post中文乱码
		request.setCharacterEncoding("utf-8");//仅作用域request体，不作用于请求行
		String name=request.getParameter("username");
		System.out.println(name);
		System.out.println(request.getContextPath());
		//把数据传递给另一个页面
		response.sendRedirect(request.getContextPath()+"/another?name="+name);
		
	}

}
